﻿using Exam.infranstuctrue.Dto.other;
using Exam.infranstuctrue.Dto.Request.Exam;
using Exam.infranstuctrue.Dto.Respones;
using Exam.infranstuctrue.Dto.Respones.Arrange;
using Exam.infranstuctrue.Dto.Respones.Exam;
using Exam.infranstuctrue.EFCore;
using Exam.infranstuctrue.IOC;
using Exam.infranstuctrue.Tools;
using Exam.infranstuctrue.Tools.Attributes;
using Exam.Infrastrucrure.Dto;
using Exam.Service.Interface;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace Exam.Service.Instance
{
    [Iinjection]
    public class ExamService : BaseService, IExamServer
    {
        private readonly ExamIOC _examIOC;

        public ExamService(ExamIOC examIOC)
        {
            _examIOC = examIOC;
        }
        /// <summary>
        /// 获取培训班
        /// </summary>
        /// <param name="trainingids"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private string GetTraining(string trainingids, string? token = null)
        {
            var uname = "";
            var baseUrl = Appsettings.GetVal(new string[] { "HttpBaseUrl" });
            string url = baseUrl + "api/TrainTask/GetTraining";
            var http = Http.Get(url, token);
            var code = JsonConvert.DeserializeObject<ApiResult>(http);
            var result = JsonConvert.SerializeObject(code.data);
            var res = JsonConvert.DeserializeObject<List<TrainingResponseDto>>(result);

            var uids = res.Select(d => d.Id).ToList();
            if (!string.IsNullOrEmpty(trainingids))
            {

                var uid = trainingids.Split(",");
                uname = "";
                foreach (var item2 in uid)
                {
                    var iq = res.Where(d => d.Id == item2).Single();
                    uname += iq.Name + ",";
                }
                uname = uname.Substring(0, uname.Length - 1);
            }
            return uname;
        }
        /// <summary>
        /// 获取课程
        /// </summary>
        /// <param name="couresids"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private string GetCourse(string couresids, string? token = null)
        {
            var uname = "";
            var baseUrl = Appsettings.GetVal(new string[] { "httpCourseUrl" });
            string url = baseUrl + "api/ACourse/GetAllCourse?page=1&&&limit=9999";
            var http = Http.Get(url, token);
            var code = JsonConvert.DeserializeObject<ApiResult>(http);
            var result = JsonConvert.SerializeObject(code.data);
            var res = JsonConvert.DeserializeObject<List<CourseCourseDto>>(result);

            var uids = res.Select(d => d.Cid).ToList();
            if (!string.IsNullOrEmpty(couresids))
            {

                var uid = couresids.Split(",");
                uname = "";
                foreach (var item2 in uid)
                {
                    var iq = res.Where(d => d.Cid == item2).Single();
                    uname += iq.Cname + ",";
                }
                uname = uname.Substring(0, uname.Length - 1);
            }
            return uname;
        }
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="orgabizationuids"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private string GetUser(string orgabizationuids, string? token = null)
        {
            var uname = "";
            var url = "https://change.qiudaoyu.top/api/Admin/GetUser/?page=1&&limit=99999";
            var users = Http.Get(url, token);
            var user = JsonConvert.DeserializeObject<MyApiResult>(users);
            var userchilren = JsonConvert.SerializeObject(user.data);
            var result = JsonConvert.DeserializeObject<MyApiResultChliren>(userchilren);
            var res = JsonConvert.SerializeObject(result.data);
            var data = JsonConvert.DeserializeObject<List<ResponseAdminDto>>(res);

            var uids = data.Select(d => d.id).ToList();
            if (!string.IsNullOrEmpty(orgabizationuids))
            {

                var uid = orgabizationuids.Split(",");
                uname = "";
                foreach (var item2 in uid)
                {
                    var iq = data.Where(d => d.id == item2).Single();
                    uname += iq.name + ",";
                }
                uname = uname.Substring(0, uname.Length - 1);
            }
            return uname;
        }
        /// <summary>
        /// 获取全部考试
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetExam(string uid)
        {
            var arrang = await _examIOC._examArrangEFCore.QueryAll(d => d.Auids.Contains(uid) && d.Atype == 1).ToListAsync();
            List<ArrangDto> arrangDtos = new List<ArrangDto>();
            foreach (var item in arrang)
            {
                arrangDtos.Add(new ArrangDto
                {
                    aid = item.Aid,
                    aname = item.Aname,
                    aexplain = item.Aexplain,
                    abegintime = item.AbeginTime,
                    aendtime = item.AendTime,
                });
            }

            return GetResult(1, "全部考试", arrangDtos);
        }
        /// <summary>
        /// 获取课程考试
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetCourseTestPage(string uid, string? token = null)
        {
            var arrang = await _examIOC._examArrangEFCore.QueryAll(d => d.Auids.Contains(uid) && d.Atype == 3).ToListAsync();
            List<ArrangDto> arrangDtos = new List<ArrangDto>();
            foreach (var item in arrang)
            {
                arrangDtos.Add(new ArrangDto
                {
                    aid = item.Aid,
                    aname = item.Aname,
                    Cname = GetCourse(item.ArelationId, token),
                    aexplain = item.Aexplain,
                    abegintime = item.AbeginTime,
                    aendtime = item.AendTime,
                });
            }

            return GetResult(1, "全部考试", arrangDtos);
        }
        /// <summary>
        /// 获取培训班考试
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetTrainingTestPage(string uid, string? token = null)
        {
            var arrang = await _examIOC._examArrangEFCore.QueryAll(d => d.Auids.Contains(uid) && d.Atype == 2).ToListAsync();
            List<ArrangDto> arrangDtos = new List<ArrangDto>();
            foreach (var item in arrang)
            {
                arrangDtos.Add(new ArrangDto
                {
                    aid = item.Aid,
                    aname = item.Aname,
                    Tname = GetTraining(item.ArelationId, token),
                    aexplain = item.Aexplain,
                    abegintime = item.AbeginTime,
                    aendtime = item.AendTime,
                });
            }
            return GetResult(1, "全部考试", arrangDtos);
        }
        /// <summary>
        /// 未考试
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetNoExam(string uid)
        {
            //得到时间未结束的安排
            var arrangs = await _examIOC._examArrangEFCore.QueryAll(d => d.Auids.Contains(uid) && d.AendTime > DateTime.Now).ToListAsync();
            //取到安排地id
            var aids = arrangs.Select(d => d.Aid).ToList();
            List<ArrangDto> answersDtos = new List<ArrangDto>();
            var answers = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.Ueid == uid).ToListAsync();
            foreach (var item2 in aids)
            {
                //答题卡中查询该安排
                var answer = answers.Where(d => d.Ueaid == item2).ToList();
                if (!answer.Any())
                {
                    var arrange = arrangs.Where(d => d.Aid == item2).Single();

                    answersDtos.Add(new ArrangDto
                    {
                        aid = arrange.Aid,
                        aname = arrange.Aname,
                        aexplain = arrange.Aexplain,
                        abegintime = arrange.AbeginTime,
                        aendtime = arrange.AendTime,
                    });
                }
            }
            return GetResult(1, "未考试数据", answersDtos);

        }
        /// <summary>
        /// 缺考
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetOverTimeExam(string uid)
        {
            var arranges = await _examIOC._examArrangEFCore.QueryAll(d => d.Auids.Contains(uid) && d.AendTime < DateTime.Now).ToListAsync();
            var aids = arranges.Select(d => d.Aid).ToList();
            List<ArrangDto> answersDtos = new List<ArrangDto>();
            var answers = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.Ueid == uid).ToListAsync();
            foreach (var item2 in aids)
            {
                //答题卡中查询该安排
                var answer = answers.Where(d => d.Ueaid == item2).ToList();
                if (!answer.Any())
                {
                    var arrange = arranges.Where(d => d.Aid == item2).Single();

                    answersDtos.Add(new ArrangDto
                    {
                        aid = arrange.Aid,
                        aname = arrange.Aname,
                        aexplain = arrange.Aexplain,
                        abegintime = arrange.AbeginTime,
                        aendtime = arrange.AendTime,
                    });
                };
            }
            return GetResult(1, "缺考数据", answersDtos);
        }
        /// <summary>
        /// 已考试
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetTestPage(string uid)
        {
            var answers = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.Ueid.Contains(uid) && d.UefinishTime != null && d.Uescore != null).ToListAsync();
            var aids = answers.Select(d => d.Ueaid).ToList();
            var arranges = await _examIOC._examArrangEFCore.QueryAll(d => aids.Contains(d.Aid)).ToListAsync();
            List<ArrangDto> arrangDtos = new List<ArrangDto>();
            if (arranges.Any())
            {
                foreach (var item in arranges)
                {
                    arrangDtos.Add(new ArrangDto
                    {
                        aid = item.Aid,
                        aname = item.Aname,
                        aexplain = item.Aexplain,
                        abegintime = item.AbeginTime,
                        aendtime = item.AendTime,
                    });
                }
                return GetResult(1, "已考试数据", arrangDtos);
            }
            return GetResult(1, "已考试数据", arrangDtos);

        }
        /// <summary>
        /// 考试进行中
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetExaming(string uid)
        {
            var answers = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.Ueid.Contains(uid) && d.UecreateTime != null && d.UefinishTime == null && d.Uescore == null).ToListAsync();
            var aids = answers.Select(d => d.Ueaid).ToList();
            var arranges = await _examIOC._examArrangEFCore.QueryAll(d => aids.Contains(d.Aid)).ToListAsync();
            List<ArrangDto> arrangDtos = new List<ArrangDto>();
            foreach (var item in arranges)
            {
                arrangDtos.Add(new ArrangDto
                {
                    aid = item.Aid,
                    aname = item.Aname,
                    aexplain = item.Aexplain,
                    abegintime = item.AbeginTime,
                    aendtime = item.AendTime,
                });
            }
            return GetResult(1, "考试进行中数据", arrangDtos);
        }
        /// <summary>
        /// 开始考试
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> BeginExam(string uid, string aid)
        {
            var arrang = await _examIOC._examArrangEFCore.QueryAll(d => d.Aid == aid).FirstOrDefaultAsync();
            if (arrang == null)
            {
                return GetResult(0, "安排ID错误");
            }
            if (arrang.AbeginTime > DateTime.Now)
            {
                return GetResult(0, "考试未开始");
            }
            if (arrang.AendTime < DateTime.Now)
            {
                return GetResult(0, "考试已结束");
            }
            var testpaper = await _examIOC._examTestPaperEFCore.QueryAll(d => arrang.Atpid == d.Tpid).SingleAsync();
            testpaper.TpuseCount = testpaper.TpuseCount + 1;
            _examIOC._examTestPaperEFCore.Update(testpaper);
            _examIOC._examTestPaperEFCore.SaveChanges();
            var uaid = Config.GUID();
            ExamUserAnswer examUserAnswer = new ExamUserAnswer();
            examUserAnswer.Uaid = uaid;
            examUserAnswer.Ueid = uid;
            examUserAnswer.Ueaid = aid;
            examUserAnswer.Uesid = "";
            examUserAnswer.Uestate = 1;
            examUserAnswer.UefinishTime = null;
            examUserAnswer.Uescore = null;
            examUserAnswer.UecreateTime = DateTime.Now;
            examUserAnswer.Uedesc = "";
            examUserAnswer.UecheckUid = "";
            _examIOC._examUserAnswerEFCore.Add(examUserAnswer);
            var result = _examIOC._examUserAnswerEFCore.SaveChanges();
            if (result > 0)
            {
                var testpage = await _examIOC._examTestPaperDetailEFCore.QueryAll(d => d.Tpdtpid == arrang.Atpid).ToListAsync();
                List<ExamUserAnswerDetail> examUserAnswerDetails = new List<ExamUserAnswerDetail>();
                foreach (var item in testpage)
                {
                    examUserAnswerDetails.Add(new ExamUserAnswerDetail
                    {
                        Uadid = Config.GUID(),
                        Uaduaid = uaid,
                        Uadqid = item.Tpdqid,
                        Uadanswer = "",
                        UadcreateTime = DateTime.Now,
                        Uadscore = null,
                        UaisRight = null,
                    });
                }
                _examIOC._examUserAnswerDetailEFCore.AddRange(examUserAnswerDetails);
                var count = _examIOC._examUserAnswerDetailEFCore.SaveChanges();
                if (count > 0)
                {
                    return GetResult(1, "请开始考试");
                }
                return GetResult(0, "添加答题卡详情出错");
            }
            return GetResult(0, "添加答题卡错误");
        }
        /// <summary>
        /// 生成试题
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetQuestion(string aid)
        {
            var arranges = await _examIOC._examArrangEFCore.QueryAll(d => d.Aid == aid).SingleAsync();
            var testpage = await _examIOC._examTestPaperDetailEFCore.QueryAll(d => d.Tpdtpid.Contains(arranges.Atpid)).ToListAsync();
            var qids = testpage.Select(d => d.Tpdqid).ToList();
            var questions = await _examIOC._examQuestionEFCore.QueryAll(d => qids.Contains(d.Qid)).ToListAsync();
            var options = await _examIOC._examoptionEFCore.QueryAll(d => qids.Contains(d.Oqid)).ToListAsync();
            List<QuestionRes> questionRes = new List<QuestionRes>();
            foreach (var item in questions)
            {
                List<OptionRes> optionRes = new List<OptionRes>();
                var option = options.Where(d => d.Oqid == item.Qid).ToList();
                foreach (var item2 in option)
                {
                    optionRes.Add(new OptionRes
                    {
                        Oid = item2.Oid,
                        Ocontent = item2.Ocontent,
                        Ocreatetime = item2.Ocreatetime,
                        OisBan = item2.OisBan,
                        OisRight = item2.OisRight,
                        Oqid = item2.Oqid,
                    });
                }
                questionRes.Add(new QuestionRes
                {
                    Qid = item.Qid,
                    Qcontent = item.Qcontent,
                    Qanalysi = item.Qanalysi,
                    Qanswer = item.Qanswer,
                    Qauthor = item.Qauthor,
                    QcreateTime = item.QcreateTime,
                    Qexplain = item.Qexplain,
                    Qlable = item.Qlable,
                    Qlv = item.Qlv,
                    Qtype = item.Qtype,
                    opiton = optionRes
                });
            }
            return GetResult(1, "生成试题", questionRes);
        }
        /// <summary>
        /// 结束考试
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> EndExam(TestPageDto dto)
        {
            float? zong = 0;
            var arrange = _examIOC._examArrangEFCore.QueryAll(d => d.Aid == dto.aid && d.Auids.Contains(dto.uid)).Single();//获取单个安排
            var answer = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.Ueaid == dto.aid && d.Ueid == dto.uid && d.UefinishTime == null).FirstOrDefaultAsync();//获取单个答题卡
            if (answer == null)
            {
                return GetResult(0, "没有需要修改的答题卡");
            }
            var testpage = await _examIOC._examTestPaperDetailEFCore.QueryAll(d => d.Tpdtpid == arrange.Atpid).ToListAsync();//获取试卷详情
            var qids = testpage.Select(d => d.Tpdqid).ToList();//获取试题ID
            var questions = await _examIOC._examQuestionEFCore.QueryAll(d => qids.Contains(d.Qid)).ToListAsync();//判断试题是否未主观
            answer.UefinishTime = DateTime.Now;//修改交卷时间
            var consume = DateTime.Now - answer.UecreateTime;
            var answerdetali = await _examIOC._examUserAnswerDetailEFCore.QueryAll(d => d.Uaduaid == answer.Uaid).ToListAsync();//通过答题卡ID获取答题详情
            var testpages = await _examIOC._examTestPaperDetailEFCore.QueryAll(d => 1 == 1).ToListAsync();//获取试卷详情
            var options = await _examIOC._examoptionEFCore.QueryAll(d => 1 == 1).ToListAsync();//获取选项

            foreach (var item in dto.option)
            {
                var question = questions.Where(d => d.Qid == item.qid).FirstOrDefault();
                if (question.QisCheck == 0)
                {
                    //不是主观
                    var answerqids = answerdetali.Where(d => d.Uadqid == item.qid).FirstOrDefault();//通过答题卡详情获取单个试题
                    var answertestpage = testpages.Where(d => d.Tpdqid == answerqids.Uadqid).FirstOrDefault();
                    var option = options.Where(d => d.Oqid == answerqids.Uadqid).ToList();//通过试题ID获取对应的选项s
                    for (int i = 0; i < option.Count(); i++)
                    {
                        if (option[i].OisRight == 1)
                        {
                            //正确答案
                            if (item.answer == i + 1)
                            {
                                //回答正确
                                answerqids.UaisRight = 1;
                                answerqids.Uadanswer = item.answer.ToString();
                                answerqids.Uadscore = answertestpage.Tpdscore;
                                zong += answertestpage.Tpdscore;
                            }
                            else
                            {
                                //回答错误
                                answerqids.UaisRight = 0;
                                answerqids.Uadscore = 0;
                                answerqids.Uadanswer = item.answer.ToString();
                            }
                        }
                        else
                        {
                            //错误答案
                            if (item.answer == i + 1)
                            {
                                //回答错误
                                answerqids.UaisRight = 0;
                                answerqids.Uadscore = 0;
                                answerqids.Uadanswer = item.answer.ToString();
                            }
                        }
                    }
                } 
                else
                {
                    //是主观
                    var answerqids = answerdetali.Where(d => d.Uadqid == item.qid).FirstOrDefault();//通过答题卡详情获取单个试题
                    answerqids.Uadanswer = item.answers;
                }
            }
            _examIOC._examUserAnswerDetailEFCore.UpdateRange(answerdetali);//修改答题卡详情
            _examIOC._examUserAnswerDetailEFCore.SaveChanges();
            answer.Uescore = zong;//统计总分

            var result = _examIOC._examQuestionBankEFCore.Transactions(_examIOC._examUserAnswerEFCore, _examIOC._examUserAnswerDetailEFCore);
            var answers = dto.option.Select(d => d.answers).First();
            if (answers == null)
            {
                answer.UeisCheck = 1;
                _examIOC._examUserAnswerEFCore.Update(answer);//修改答题卡
                _examIOC._examUserAnswerEFCore.SaveChanges();
                if (result == true)
                {
                    return GetResult(1, "交卷成功", data: (new
                    {
                        score = zong,
                        consume = consume
                    }));
                }
            }
            answer.UeisCheck = 0;
            _examIOC._examUserAnswerEFCore.Update(answer);//修改答题卡
            _examIOC._examUserAnswerEFCore.SaveChanges();
            return GetResult(0, "交卷成功,包含客观题请次日观看成绩", consume);
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> ExamParticulars(string aid)
        {
            if (aid == "")
            {
                return GetResult(0, "参数错误");
            }
            var arrange = await _examIOC._examArrangEFCore.QueryAll(d => d.Aid == aid).FirstOrDefaultAsync();
            var answer = await _examIOC._examUserAnswerEFCore.QueryAll(o => o.UecreateTime, false, d => d.Ueaid.Contains(aid)).FirstOrDefaultAsync();
            if (answer == null)
            {
                return GetResult(0, "参数错误");
            }
            var testpaper = await _examIOC._examTestPaperEFCore.QueryAll(d => d.Tpid == arrange.Atpid).FirstOrDefaultAsync();
            var answerdeli = await _examIOC._examUserAnswerDetailEFCore.QueryAll(d => d.Uaduaid == answer.Uaid).ToListAsync();
            var qids = answerdeli.Select(d => d.Uadqid).ToList();
            var questions = await _examIOC._examQuestionEFCore.QueryAll(d => qids.Contains(d.Qid)).ToListAsync();
            var options = await _examIOC._examoptionEFCore.QueryAll(d => qids.Contains(d.Oqid)).ToListAsync();
            List<AnswerDetailsRes> answerDetailsRes = new List<AnswerDetailsRes>();
            foreach (var item3 in answerdeli)
            {
                var question = questions.Where(d => d.Qid == item3.Uadqid);
                List<QuestionRes> questionRes = new List<QuestionRes>();
                foreach (var item2 in question)
                {
                    List<OptionRes> optionRes = new List<OptionRes>();
                    var option = options.Where(d => d.Oqid == item2.Qid).ToList();
                    foreach (var item in option)
                    {
                        optionRes.Add(new OptionRes
                        {
                            Ocontent = item.Ocontent,
                            Oid = item.Oid,
                            OisRight = item.OisRight,
                            Oqid = item.Oqid
                        });
                    }
                    questionRes.Add(new QuestionRes
                    {
                        Qid = item2.Qid,
                        Qcontent = item2.Qcontent,
                        Qexplain = item2.Qexplain,
                        Qanswer = item2.Qanswer,
                        Qanalysi = item2.Qanalysi,
                        Qlable = item2.Qlable,
                        Qlv = item2.Qlv,
                        opiton = optionRes
                    });

                    answerDetailsRes.Add(new AnswerDetailsRes
                    {
                        qid = item2.Qid,
                        zscore = testpaper.TptotalScore,
                        answer = item3.Uadanswer,
                        isrtight = item3.UaisRight,
                        score = item3.Uadscore,
                        question = questionRes
                    });
                }
            }
            return GetResult(1, "详情", answerDetailsRes);
        }
        /// <summary>
        /// 考试排名
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> ExamRanking(string aid, string uid, string? token)
        {

            var answer = await _examIOC._examUserAnswerEFCore.QueryAll(o => o.Uescore, false, d => d.Ueaid.Contains(aid)).ToListAsync();
            var user = await _examIOC._examUserAnswerEFCore.QueryAll(d => d.UecreateTime, false, o => o.Ueaid == aid && o.Ueid == uid).FirstOrDefaultAsync();
            List<RankingResChilren> chilren = new List<RankingResChilren>();
            RankingRes rankingRes = new RankingRes();
            foreach (var item in answer)
            {
                if (item.UefinishTime != null)
                {
                    if (item.Ueid == user.Ueid)
                    {
                        rankingRes.ranking = answer.IndexOf(item) + 1;
                    }
                    var time = (Convert.ToDateTime(item.UefinishTime) - Convert.ToDateTime(item.UecreateTime));
                    var date = time.TotalSeconds;
                    chilren.Add(new RankingResChilren
                    {
                        Othername = GetUser(item.Ueid, token),
                        OtherID = item.Ueid,
                        Otherscore = item.Uescore,
                        Otherconsume = date,
                    });
                }
            }

            if (user != null)
            {
                if (user.UefinishTime != null)
                {
                    var utime = (Convert.ToDateTime(user.UefinishTime) - Convert.ToDateTime(user.UecreateTime));
                    var udate = utime.TotalSeconds;
                    rankingRes.name = GetUser(user.Ueid, token);
                    rankingRes.id = uid;
                    rankingRes.score = user.Uescore;
                    rankingRes.consume = udate;
                    rankingRes.chilern = chilren;

                }
                return GetResult(1, "排名", rankingRes);
            }

            else
            {
                rankingRes.chilern = chilren;
            }
            return GetResult(1, "排名", rankingRes);
        }
        /// <summary>
        /// 获取单个试卷
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        public async Task<ApiResult> GetEchoTestPage(string aid)
        {
            var arrang = await _examIOC._examArrangEFCore.QueryAll(d => d.Aid == aid).FirstOrDefaultAsync();
            var question = _examIOC._examTestPaperEFCore.QueryAll(d => d.Tpid == arrang.Atpid).Single();
            List<TestPaperRes> questionRes = new List<TestPaperRes>();
            questionRes.Add(new TestPaperRes
            {
                tpname = question.Tpname,
                tpexplain = question.Tpexplain,
                tplabel = question.Tpexplain,
                tplv = question.Tplv,
                score = question.TptotalScore,
                passscore = question.TppassScore,
                begintime = arrang.AbeginTime,
                endtime = arrang.AendTime,
            });
            return GetResult(1, "单个试卷", questionRes);
        }
    }
}
